#define _CRT_SECURE_NO_WARNINGS
#pragma once

#include <iostream>
#include <mysql/mysql.h>


class Connection{
public:
    //初始化连接
    Connection();
    
    ~Connection();

    bool connect(std::string ip,
        unsigned short port,
        std::string user,
        std::string password,
        std::string dbname
    );

    //更新 insert delete update
    bool update(std::string sql);

    //查询 select
    MYSQL_RES* query(std::string sql);

    //刷新连接时间
    void refreshAliveTime(){
        _alivetime = clock();
    }

    clock_t getAliveTime(){
        return clock();
    }

private:
    MYSQL* _conn;
    clock_t _alivetime;

};